﻿/* Created by: Vinnie
 * Contact:  */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace TravelExpertsManagementConsole
{
    class AccessBooking
    {
       private SqlConnection _myConn;
       private SqlCommand _myCommand;
            
       public AccessBooking()
       {            
        _myConn = new SqlConnection("server=(local);database=TravelExperts;integrated security=SSPI");
        _myCommand = new SqlCommand();
        _myCommand.Connection = _myConn;
       }

       public List<Booking> Select()
        {
            List<Booking> myBookings = new List<Booking>();
            _myCommand.CommandText = "SELECT * FROM BookingDetails";

            try {
                _myConn.Open();
                SqlDataReader reader = _myCommand.ExecuteReader();

                //read the reader
                while (reader.Read())
                {
                    Booking getData = new Booking();
                    getData.AgencyCommission = reader.GetDecimal(7);
                    getData.BasePrice = reader.GetDecimal(6);
                    getData.Description = reader.GetString(4);
                    getData.Destination = reader.GetString(5);
                    getData.TripEnd = reader.GetDateTime(3);
                    getData.TripStart = reader.GetDateTime(2);

                    myBookings.Add(getData);
                }
            }
            catch(SqlException ex) {
                throw ex;
            }
            finally {
                _myConn.Close();
            }
            
            return myBookings;
        }

    }
}
